import java.util.Scanner;

public class View {
    Service houseview=new Service(10);
    Scanner scanner=new Scanner(System.in);
    private void updateview(){
        System.out.println("========修改信息========");
        System.out.println("请输入你要修改的编号");
        int choice=scanner.nextInt();
        scanner.nextLine();
        houseview.uodate(choice);
    }
    private void findview(){
        System.out.println("请输入你要查找的编号");
        int id=scanner.nextInt();
        scanner.nextLine();
        houseview.find(id);
    }
    private void subvier(){
        boolean l=false;
        System.out.println("请选择要删除的房屋编号(-1退出)");
        do{
        int choice=scanner.nextInt();
        scanner.nextLine();
            if(choice>0&&choice<houseview.getId()){
                System.out.println("确定删除吗？y/n");
                String tem=scanner.nextLine();
                if(tem.equals("n")){
                    System.out.println("已退出");
                    break;
                }
            }
            if(choice==-1){
                System.out.println("成功退出");
                break;
            }
        if(houseview.sub(choice)){
            System.out.println("删除成功");
        }else {
            System.out.println("无该编号请重新输入");
            l=true;
        }
        }while (l);
    }
    private void addview(){
        System.out.println("=====添加房屋====");
        System.out.println("姓名:");
        String name=scanner.nextLine();
        System.out.println("电话:");
        String phone=scanner.nextLine();
        System.out.println("地址:");
        String address=scanner.nextLine();
        System.out.println("月租:");
        int rent=scanner.nextInt();
        scanner.nextLine();
        System.out.println("状态:");
        String state=scanner.nextLine();
        House house=new House(houseview.getId(),name,phone,address,rent,state);
        houseview.add(house);
    }
    public void list() {
        System.out.println("编号  房主  电话  地址  月租  状态(未出租/已出租)");
        House[] house=houseview.serlist();
        for (int i = 0; i < house.length; i++) {
            if(house[i]==null){
                break;
            }
            System.out.println(house[i]);
        }
    }
    public void viewmain(){

        boolean loop=true;
        do{
            System.out.println("======房屋出租菜单=======");
            System.out.println("  1新增房源");
            System.out.println("  2.查找房屋");
            System.out.println("  3.删除房屋信息");
            System.out.println("  4.修改房屋信息");
            System.out.println("  5.房屋列表");
            System.out.println("  6.退出系统");
            System.out.println("请选择:");
            int choice=scanner.nextInt();
            scanner.nextLine();
            switch (choice){
                case 1:
                    addview();
                    break;
                case 2:
                    findview();
                    break;
                case 3:
                    subvier();
                    break;
                case 4:
                    updateview();
                    break;
                case 5:
                    list();
                    break;
                case 6:
                    System.out.println("成功退出系统");
                    return;
            }
        }while (true);
    }
}
